# encoding: UTF-8
'''
Created on 2013年11月12日

@author: xuben
主城
'''

from ..common import Command, RequestModel, Logger
from ..common.SocketService import gameSocketService
import MaincityData

class MaincityGetInfoRequest(RequestModel.RequestModel):
    '''
    classdocs
    '''
    
    def setCommand(self):
        self.command = Command.GET_MAINCITY_INFO
        
    def onReceive(self, data):
        MaincityData.updateResourceRegionRough(data)
        
class ResourceRegionGetInfoRequest(RequestModel.RequestModel):
    
    def setCommand(self):
        self.command = Command.GET_RESOURCE_REGION_INFO
        
    def onReceive(self, data):
        MaincityData.updateResourceRegionDetail(data)
        
'''
获取政务事件信息
'''
class PoliticalEventGetInfoRequest(RequestModel.RequestModel):
    
    def setCommand(self):
        self.command = Command.GET_POLITICAL_EVENT_INFO
        
    def onReceive(self, data):
        MaincityData.updatePoliticalEvent(data)
        
'''
处理政务事件
'''
def dealPoliticalEvent(buildingId, option):
    command = Command.DEAL_POLITICAL_EVENT
    params = 'autoClose=0&buildingId='+str(buildingId)+'&option='+str(option)
    gameSocketService.send(command, params, dealPoliticalEventCallback)

'''
处理政务事件回调函数
'''
def dealPoliticalEventCallback(data):
    if 'eventReward' in data:
        for rewardObj in data['eventReward']:
            if 'type' in rewardObj and 'value' in rewardObj:
                Logger.log('处理政务事件, type:' + str(rewardObj['type']) + ', value:' + str(rewardObj['value']), output = True)